#include <stdio.h>
#include "sc.h"
#include "timer.h"

#define OUTSTREAM stdout
#define TRIALS 100

typedef int STREAMPTR;

PixelToPixelOp()
pass(in stream unsigned char *i,
     out stream unsigned char *o)
{
}

PixelToPixelOp()
split(in stream unsigned char *i,
      out stream unsigned char *o1,
      out stream unsigned char *o2)
{
}

PixelToPixelOp()
merge(in stream unsigned char *i1,
      in stream unsigned char *i2,
      out stream unsigned char *o)
{
}

GlobalOp()
gpass(in stream unsigned char **i,
      out stream unsigned char **o)
{
}

GlobalOp()
gsplit(in stream unsigned char **i,
       out stream unsigned char **o1,
       out stream unsigned char **o2)
{
}

GlobalOp()
gmerge(in stream unsigned char **i1,
       in stream unsigned char **i2,
       out stream unsigned char **o)
{
}

int MAIN(int argc, char **argv)
{
  int i=0;
  STREAMPTR a=1, b=2, c=3, d=4, e=5, f=6, g=7;
  tmr_t timer = tmrInit();

  scInit(argc, argv);

  for (i=0; i < TRIALS; i++)
  {
    tmrStart(&timer);   

    generate(scint(0), a);

    split(a, a, b);
    pass(a, a);
    split(b, b, c);
    pass(b, b);
    merge(a, b, a);
    pass(a, a);
    merge(a, c, a);

    discard(a);

    tmrStop(&timer);
    fprintf(OUTSTREAM, "T(%d, %d) = %f;\n", 1, i+1, tmrGetValueInUs(&timer)/1000.0);

    _schedule(0);

    tmrStop(&timer);
    fprintf(OUTSTREAM, "T(%d, %d) = %f;\n", 2, i+1, tmrGetValueInUs(&timer)/1000.0);

    _awaitall();

    tmrStop(&timer);
    fprintf(OUTSTREAM, "T(%d, %d) = %f;\n", 3, i+1, tmrGetValueInUs(&timer)/1000.0);
  }

  for (i=0; i < TRIALS; i++)
  {
    tmrStart(&timer);   

    generate(scint(1024), a);

    gsplit(a, a, b);
    gpass(a, a);
    gsplit(b, b, c);
    gpass(b, b);
    gmerge(a, b, a);
    gpass(a, a);
    gmerge(a, c, a);

    discard(a);

    tmrStop(&timer);
    fprintf(OUTSTREAM, "T(%d, %d) = %f;\n", 4, i+1, tmrGetValueInUs(&timer)/1000.0);

    _schedule(0);

    tmrStop(&timer);
    fprintf(OUTSTREAM, "T(%d, %d) = %f;\n", 5, i+1, tmrGetValueInUs(&timer)/1000.0);

    _awaitall();

    tmrStop(&timer);
    fprintf(OUTSTREAM, "T(%d, %d) = %f;\n", 6, i+1, tmrGetValueInUs(&timer)/1000.0);
  }

  for (i=0; i < TRIALS; i++)
  {
    tmrStart(&timer);   

    generate(scint(1024), a);

    split(a, a, b);
    pass(a, a);
    split(b, b, c);
    pass(b, b);
    merge(a, b, a);
    pass(a, a);
    merge(a, c, a);

    discard(a);

    tmrStop(&timer);
    fprintf(OUTSTREAM, "T(%d, %d) = %f;\n", 7, i+1, tmrGetValueInUs(&timer)/1000.0);

    _schedule(0);

    tmrStop(&timer);
    fprintf(OUTSTREAM, "T(%d, %d) = %f;\n", 8, i+1, tmrGetValueInUs(&timer)/1000.0);

    _awaitall();

    tmrStop(&timer);
    fprintf(OUTSTREAM, "T(%d, %d) = %f;\n", 9, i+1, tmrGetValueInUs(&timer)/1000.0);
  }

  return scExit();
}
